﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DesignParttenSamples
{
    public enum SeasonEnum
    {
        Spring,
        Summer,
        Autumn,
        Winter
    }

    public class SeasonCalendar
    {
        static IDictionary<SeasonEnum, SeasonMonthEntry> monthLookup = new Dictionary<SeasonEnum, SeasonMonthEntry>();

        SeasonMonthEntry entry;

        struct SeasonMonthEntry
        {
            public SeasonEnum Season { get; set; }
            public int StartMonth { get; set; }
            public int EndMonth { get; set; }
            public string Note { get; set; }
        }

        static SeasonCalendar()
        {
            monthLookup.Add(SeasonEnum.Spring, new SeasonMonthEntry
            {
                Season = SeasonEnum.Spring,
                StartMonth = 1,
                EndMonth = 3,
                Note = "生机盎然"
            });
            
            monthLookup.Add(SeasonEnum.Summer, new SeasonMonthEntry
            {
                Season = SeasonEnum.Summer,
                StartMonth = 4,
                EndMonth = 6,
                Note = "烈日炎炎"
            });
            monthLookup.Add(SeasonEnum.Autumn, new SeasonMonthEntry
            {
                Season = SeasonEnum.Autumn,
                StartMonth = 7,
                EndMonth = 9,
                Note = "硕果累累"
            });
            monthLookup.Add(SeasonEnum.Winter, new SeasonMonthEntry
            {
                Season = SeasonEnum.Winter,
                StartMonth = 10,
                EndMonth = 12,
                Note = "冰天雪地"
            });

        }

        public SeasonCalendar(SeasonEnum season)
        {
            
            entry = monthLookup[season];
        }

        public SeasonEnum Season { get { return entry.Season; } }
        public int StartMonth { get { return entry.StartMonth; } }
        public int EndMonth { get { return entry.EndMonth; } }
        public string Note { get { return entry.Note; } }

        public static SeasonEnum GetSeason(int month)
        {
            if (month > 12 || month < 1)
            {
                throw new NotSupportedException();
            }
            int startMonth = ((month - 1) / 3) * 3 + 1;
            return monthLookup.Values.FirstOrDefault(x => x.StartMonth == startMonth).Season;
        }
    }
}
